import Vue from 'vue'
import Vuex from 'vuex'
import classifyy from './category/classifyy'
import Cart from "./cart/cart"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
	  bannerList : []  ,//首页轮播图
	  kanjiaList : []  ,//全民砍价字体下面的数据
	  swiperList : []  ,//精选横向
	  ZhuaninnerList : [],
	  cateList : [],
	  firstLevel : [],
	  secondLevel : []
  },
  mutations: {
	  Get_data(state,items){
	  	state.cateList = [...items];
	  	state.firstLevel.push({name:"所有分类"})
	  	items.forEach((element) => {
	  		if(element.pid === 0){
	  			state.firstLevel.push(element)
	  		} else {
	  			state.secondLevel.push(element)
	  		}
	  	})
	  },
	  Get_data_two(state,item){
	  	state.secondLevel = [];
	  	if(item.name === "所有分类"){
	  		state.cateList.forEach((element) => {
	  			if(element.pid != 0){
	  				state.secondLevel.push(element)
	  			}
	  		})
	  	} else {
	  		state.cateList.forEach((element) => {
	  			if(element.id === item.id){
	  				state.secondLevel.push(element)
	  			}
	  		})
	  	}
	  }
  },
  actions: {
	  Get_data(context){
	  	APIClient.ShopClassifyList().then(res => {
	  		context.commit("Get_data",res.data.data)
	  	})
	  },
	  Get_data_two(context,item){
	  	context.commit("Get_data_two",item)
	  }
  },
  modules: {
	  classifyy,Cart
  }
})
